package com.woniuxy.house.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.entity.house.Building;
import com.woniuxy.entity.house.dto.BuildingDto;
import com.woniuxy.entity.house.dto.BuildingInfoDto;
import com.woniuxy.entity.house.dto.SelectBuildingDto;
import com.woniuxy.house.mapper.BuildingMapper;
import com.woniuxy.house.service.BuildingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangyu
 * @since 2021-03-19
 */
@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService {

    @Autowired
    private BuildingMapper buildingMapper;

    /**
     * 根据楼盘id查询户型然后查询其租房、二手房
     * @param longitude
     * @param latitude
     */
    @Override
    public BuildingDto findDtoByMap(BigDecimal longitude, BigDecimal latitude) {
        int bid = buildingMapper.findBidByMap(longitude, latitude);
        return buildingMapper.findDtoByBid(bid);
    }

    /**
     * 新增楼盘
     * @param building 楼盘信息
     * @return
     */
    @Override
    public boolean insertBuilding(Building building) {
        return buildingMapper.insert(building) > 0;
    }

    /**
     * 删除楼盘
     * @param id 楼盘id
     * @return
     */
    @Override
    public boolean deleteBuilding(int id) {
        Building building = new Building();
        building.setId(id);
        building.setStatus(1);
        return buildingMapper.updateById(building) > 0;
    }


    /**
     * 按地址查询楼盘
     * @param current
     * @param size
     * @param address
     * @return
     */
    @Override
    public Page<Building> findByAddress(int current, int size, String address) {
        return null;
    }

    /**
     * 按价格范围查询楼盘
     * @param current
     * @param size
     * @param min
     * @param max
     * @return
     */
    @Override
    public Page<Building> findByPrice(int current, int size, int min, int max) {
        return null;
    }

    /**
     * 查询所有展示的楼盘信息，楼盘信息，户型信息，推荐经纪人
     * @return
     */
    @Override
    public List<BuildingInfoDto> findAllBuilding(int current, int size) {
        Page<BuildingInfoDto> page = new Page<>(current,size);
        List<BuildingInfoDto> buildingInfoDtoPage =buildingMapper.findAllBuilding(page);
        return buildingInfoDtoPage;
    }

    /**
     * 条件分页查询
     * @param current
     * @param size
     * @param selectBuildingDto
     * @return
     */
    @Override
    public List<BuildingInfoDto> findByCondictions(int current, int size, SelectBuildingDto selectBuildingDto) {
        Page<BuildingInfoDto> page = new Page<>(current,size);
        List<BuildingInfoDto> buildingInfoDtos = buildingMapper.findByConditions(page,selectBuildingDto);
        return buildingInfoDtos;
    }
}
